﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Share/Index.Master" Inherits="System.Web.Mvc.ViewPage<dynamic>" %>

<asp:Content ID="Content1" ContentPlaceHolderID="MainContent" runat="server">
<script type="text/javascript" language="JavaScript">
    var IncomeExpenses = { ie_id: 0, ie_uid: 0, ie_money: 0, ie_state: 0, ie_remark: '', ie_time: new Date(), ie_user: 0, ie_addTime: new Date() };
    var mylist;
    var regular_input = {
        ie_uid: { exp: /^[0-9]\d*$/, m: "请选择会员" },
        ie_money: { exp: /^(\-|\+)?\d+(\.\d+)?$/, m: "请输入正确金额" },
        ie_time: { exp: /^.{1,20}$/, m: "请输入交易发生日期" },
        ie_state: { exp: /^[0-9]\d*$/, m: "请选择是否进行余额计算" }
    }
   
    var mainForm = "";
    $(document).ready(function () {
        mainForm = $("#mainForm").html();
        mylist = new TurnPage("mylist");
        mylist.pageSize = 8;
        mylist.callback = function () { ajax(); };

        //保存明细
        $("input[name='buttEdit1']").click(function () {
            if (!$.checkFormValid("mainForm")) return false;
            $.fillObj(IncomeExpenses, "#mainForm");

            $.post("/userCard/saveIncomeExpenses.html", { IncomeExpenses: $.toJSON(IncomeExpenses) }, function (dta) {
                alert("保存成功");
                $("input[name=buttReset]").click();
                ajax();
            });
        });
        ajax();
        $("input[name=buttReset]").click(function () {
            $("input[name=ie_uid]").val('');
            $("#uname").val('');
            $("select[name=ie_state]").val('');
            $("input[name=ie_money]").val('');
            $("input[name=ie_remark]").val('');
            $("input[name=buttEdit1]").val('新增');
        });

        $("input[name=buttSeek]").click(function () {
            mylist.currPage = 1;
            ajax();
        });
    });
    function del(id) {
        if (confirm("确认删除？")) {
            $.post("/userCard/deleteIncomeExpenses.html", { res: id }, function (dta) {
                alert("删除成功");
                $("input[name=buttSeek]").click();
                ajax();
            });
        }
    }
    function edit(id) {
        $.post("/userCard/getIncomeExpensesbyid.html", { res: id }, function (dta) {
            IncomeExpenses = $.evalJSON(dta);
            IncomeExpenses.ie_time = IncomeExpenses.ie_time.Format("yyyy-MM-dd");
            $.fillForm(IncomeExpenses, "#mainForm");
            $.post("/userCard/getUserName.html", { uid: IncomeExpenses.ie_uid }, function (d) {
                $("#uname").val(d);
            });
        });
        
        $("input[name=buttEdit1]").val('修改');
    }

    function ajax() {
        var in_s = $.trim($("#seekForm :input[name=in_s]").val());
        var in_e = $.trim($("#seekForm :input[name=in_e]").val());
        var name = $("#seekForm :input[name=txtname]").val();
        var nick = $.trim($("#seekForm :input[name=txtnick]").val());
        var param = { pagesize: mylist.pageSize, pageno: mylist.currPage, in_s: in_s, in_e: in_e, name: name, nick: nick };
        $.fillObj(param, "#seekForm");
        $.post("/userCard/getIncomeExpenses.html?" + (new Date()).getTime(), param, function (data) {
            data = $.evalJSON(data);
            if (mylist.currPage == 1) {
                mylist.total = $.grep(data, function (n, i) { return typeof (n.total) == "number"; })[0].total;
                data = $.grep(data, function (n, i) { return typeof (n.total) == "undefined"; });
            }
            loadDta(data);
        });
    }

    var loadDta = function (list) {
        var sp = [];
        $("#mainTable tbody[name=mainlist]").html("");
        $.each(list, function (i, n) {
            sp.push('<tr>');
            sp.push('<td>' + n.u_name + '</td>');
            sp.push('<td>' + n.ie_money + '</td>');
            sp.push('<td>' + n.ie_statetext + '</td>');
            sp.push('<td>' + n.ie_remark + '</td>');
            sp.push('<td>' + n.ie_time.Format("yyyy-MM-dd") + '</td>');
            sp.push('<td>'+n.oper+'</td>');
            sp.push('<td><a href="#mainForm" onclick="edit(' + n.ie_id + ')" name="linkEdit" vid="' + n.ie_id + '">修改</a>  <a href="#" onclick="del(' + n.ie_id + ')" name="linkDel" >删除</a></td>');
            sp.push('</tr>');
        });
        $("#mainTable tbody[name=mainlist]").append(sp.join(''));
        //if (sp.length == 0) alert('没有符合条件的数据');
        $("#pager").html(mylist.getOutput());
    }

    //查询会员
    function seekSeller() {
        var obj = $(":text[name=_txt_name]")[0], name;
        var obj1 = $(":text[name=_txt_nick]")[0], nick;
        if (obj)
            name = $.trim(obj.value);
        if (obj1)
            nick = $.trim(obj1.value);
        var sb = [];

        sb.push('亲，输入条件查询后,请双击选择会员~');
        sb.push('<table style="width:350px;cursor:hand;" cellspacing="0">');
        sb.push('<th>');
        sb.push('姓名：<input type="text" style="width:60px"  name="_txt_name"/>');
        sb.push('</th>');
        sb.push('<th>');
        sb.push('登录名:<input type="text" style="width:60px"  name="_txt_nick"/>');
        sb.push('<a href="javascript:void(0);" onclick="seekSeller()">查 询</a>');
        sb.push('</th>');

        $.post("/userCard/getUserInfolist.html", { name: name, nick: nick }, function (dta) {
            $.each($.evalJSON(dta), function (i, o) {
                sb.push("<tr ondblclick='selectUser(" + o.u_id + ",\"" + o.u_name + "\")'><td>" + o.u_nick + "</td><td>" + o.u_name + "</td></tr>");
            });
            sb.push('</table>');
            popLayer.show("", sb.join(''), " ", false, "");
        });
    }
    function selectUser(id,name) {
        $("#mainForm :input[name=ie_uid]").val(id);
        $("#uname").val(name);
        popLayer.close();
    }
</script>
<body>
    <table width="100%" cellspacing="0" id="seekForm">
        <tr>
            <th>
                会员收支明细查询
            </th>
        </tr>
        <tr>
            <td>
                 中文名：<input type="text" name="txtname" />
                 登陆名：<input type="text" name="txtnick" />
                 交易发生日期：<input type="text"  size="15" name="in_s"  value="<%=System.DateTime.Now.AddMonths(-1).ToString("yyyy-MM-dd") %>" class="date" />
                 至<input type="text" size="15" name="in_e"  value="<%=System.DateTime.Now.ToString("yyyy-MM-dd")  %>" class="date" />
                                                   <script type="text/javascript">
                                                       $(document).ready(function () {
                                                           $(function () {
                                                               $("#seekForm :input[name=in_s]").datepicker({
                                                                   duration: '',
                                                                   showTime: false,           //日期控件是否显示时间
                                                                   constrainInput: false,
                                                                   stepMinutes: 1,
                                                                   stepHours: 1,
                                                                   altTimeField: '',
                                                                   changeMonth: true,
                                                                   yearRange: '-40:+1',changeYear: true,
                                                                   time24h: true  //是否是24h制
                                                               });
                                                           });
                                                           $(function () {
                                                               $("#seekForm :input[name=in_e]").datepicker({
                                                                   duration: '',
                                                                   showTime: false,           //日期控件是否显示时间
                                                                   constrainInput: false,
                                                                   stepMinutes: 1,
                                                                   stepHours: 1,
                                                                   altTimeField: '',                                            
                                                                   changeMonth: true,
                                                                   yearRange: '-40:+1',changeYear: true,
                                                                   time24h: true  //是否是24h制
                                                               });
                                                           });
                                                       });
                     </script>
                <input type="button" name="buttSeek" value="查询" onclick="" class="btn1" />
            </td>
        </tr>
    </table>
    <table cellspacing="0"   id="mainTable">
        <caption style="color: red; font-size: 15px; font-weight: bold">
            会员收支明细列表</caption>
        <tr>
            <th width="30">
                中文名
            </th>
            <th width="30">
                涉及金额
            </th>
            <th width="80">
                是否进行余额计算
            </th>
            <th width="80">
                备注
            </th>
            <th width="120">
                交易发生日期
            </th>
            <th>
            操作人
            </th>
            <th width="30">
            </th>
        </tr>
        <tbody name="mainlist">
        </tbody>
    </table>
    <div id="pager" class="pager">
    </div>
    <table cellspacing="0" id="mainForm">
        <caption>
            编辑收支明细</caption>
        <tr>
            <th colspan="3">
                编辑收支明细
            </th>
        </tr>
         <tr>
            <td>会员*</td>
            <td>
            <input type="hidden" name="ie_uid"/>
            <input type="text" readonly="readonly" id="uname"/>
            <a href="javascript:void(0);" onclick="seekSeller()" style="cursor:hand;" >点此选择会员</a>
            </td>
            <td><span class="tsxx"></span></td>
        </tr>
        <tr>
            <td>涉及金额*</td>
            <td><input type="text" name="ie_money" />
            </td>
            <td><span class="tsxx"></span></td>
        </tr>
         <tr>
            <td>备注</td>
            <td><input type="text" name="ie_remark" /></td>
            <td><span class="tsxx"></span></td>
        </tr>
         <tr>
            <td>否进行余额计算*</td>
            <td><select name="ie_state">
                    <option value="">请选择</option>
                    <%
                        foreach (string s in Enum.GetNames(typeof(DAL.Enums.iestate)))
                        {
                            int _v = (int)Enum.Parse(typeof(DAL.Enums.iestate), s);
                            Response.Write("<option value='" + _v + "'>" + s + "</option>");
                        }
                    %>
                </select>
            </td>
            <td><span class="tsxx"></span></td>
        </tr>
        <tr>
            <td>
                交易发生日期
            </td>
            <td>
                <input type="text" value="<%=System.DateTime.Now.ToString("yyyy-MM-dd") %>" name="ie_time" />
            </td>
            <script type="text/javascript">
                $(document).ready(function () {
                    $(function () {
                        $('#mainForm :text[name=ie_time]').datepicker({
                            numberOfMonths: 1,
                            showButtonPanel: true, 
                            changeMonth: true,
                            yearRange: '-40:+1',changeYear: true
                        });
                    });
                });
            </script>
            <td>
                <span class="tsxx"></span>
            </td>
        </tr>
        <tr class="main-status" id="mainstatus" style="display: none">
            <td colspan="3" class="bbd-bj-bom" align="center" height="41">
                正在验证表单....
            </td>
        </tr>
        <tr class="main-sub" id="mainsub">
            <td colspan="3" class="bbd-bj-bom" align="center" height="41">
                <input type="button" name="buttEdit1" class="btn1" style="width: 200px" value="新增" />
                <input type="button" name="buttReset" class="btn1" style="width: 200px" value="重置" />
            </td>
        </tr>
    </table>
</body>

</asp:Content>
